<style scoped>
  .weui-media-box_appmsg .weui-media-box__hd {
    font-size: 12px;
    /*background: #ccc;*/
    color: #fff;
  }
  .weui-media-box_appmsg .weui-media-box__hd .blue {
    background: #296BCC !important;
  }
  .weui-media-box__desc {
    font-size: 12px;
  }
  .weui-media-box__title {
    white-space: normal;
    font-size: 14px;
    margin-bottom: 5px;
  }
  .weui-form-preview__bd {
    text-align: left;
  }

  .weui-form-preview {
    position: relative;
    background-color: #fff;
    margin: 1%;
    border-radius: 5px;
  }
  .time {
    position: absolute;
    right: 15px;
    top: 0;
    font-size: 10px;
    color: #ccc;
  }

  .logimg {
    width: 14px;
    height: 14px;
  }
  .datalist {
    background: #e3e3e3;
    height: 100%;
    overflow: hidden;
  }
  .datalist.nodata {
    font-size: 14px;
    padding: 5px;
  }

  .weui-media-box_appmsg {
    /*display: block !important;*/
    font-size: 0;
  }
  .weui-media-box_appmsg .weui-media-box__hd {
    margin-right: 3% !important;
    width: 23%;
    height: 23%;
    white-space: nowrap;
    /*line-height: 23%;*/
    display: inline-block !important;
  }
  .weui-media-box_appmsg .weui-media-box__bd {
    display: inline-block !important;
    width: 71%;
  }
  .weui-media-box__desc {
    overflow: initial;
    line-height: 1.4;
    display: flex;
  }
  .weui-media-box_appmsg .weui-media-box__hd .nodenm{
    width: 50px;
    height: 50px;
    line-height: 50px;
    border-radius: 50%;
    background: #ccc;
    margin: 0 auto;
    font-size: 10px;
  }

  .delsty {
    position: absolute;
    top: -10px;
    right: -15px;
    /*z-index: 1000;*/
  }
  .icontbox {
    font-size: 0;display: flex;
  }
  .contbox-h4 {
    width: 50%;display: inline-block;
  }
  .contbox-txt {
    width: 50%; display: inline-block;font-size: 10px; color: #ccc;
  }
</style>
<template>
  <div class="logs">
    <div class="rj-wrap">
      审批记录
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px" />
      </a>
    </div>

    <div style="overflow:auto;overflow-x: hidden;" v-show="nodes.length > 0" id="wrap">
      <div class="weui-form-preview" v-for="(item, index) in nodes">
        <div class="weui-form-preview__bd">
          <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
            <div class="weui-media-box__hd" style="overflow: hidden;">
              <div class="nodenm"  :class="item.status == 2 ? 'blue' : ''">{{item.name}}</div>
            </div>
            <div class="weui-media-box__bd" style="position: relative;">
              <div class="delsty" v-show="showEdit(item.operators, item.status)" @click="editIt(item.optlogid)"><img src="@/assets/icon-edit.png" style="width: 20px;" /> </div>
              <p class="time">{{filterNull(item.logs).createtime}}</p>
              <h4 class="weui-media-box__title" v-if="item.operators.length <= 1" v-for="(oper, i) in item.operators">{{oper.realname}}</h4>
              <h4 class="weui-media-box__title" v-if="item.operators.length > 1"><span v-for="(oper2, i) in item.operators">{{oper2.realname}}<i v-show="i+1 != item.operators.length"> / </i></span></h4>
              <p class="weui-media-box__desc">{{filterNull(item.logs).description}}</p>
              <div class="exp uploaderFiles" style="display: inline-block;padding-top: 5px;" v-if="item.logs != null && item.logs.imgs.length > 0">
                <img class="logimg" style="padding-right: 5px;"  v-for="(image, index) in item.logs.imgs" :key="image.guid"  alt="" onerror="javascript:this.src='../../../static/image/default.png';this.onerror = null" :src="image.url + '-suolue.png'" :data-img="image.url + '.png'" />
              </div>
              <template  v-if="item.appendRemark != ''" v-for="(remark, index) in packIt(item.appendRemark)">
                <div class="icontbox" style="border-top: 0.5px solid #eee;margin-top: 5px;">
                  <h4 class="weui-media-box__title contbox-h4">{{remark.operator}}</h4>
                  <p class="contbox-txt">{{remark.appendDate}}</p>
                </div>
                <p class="weui-media-box__desc" style="margin-bottom: 5px;">{{remark.remark}}</p>
              </template>
            </div>
          </a>
        </div>
      </div>
      <div class="weui-loadmore weui-loadmore_line">
        <span class="weui-loadmore__tips">没有更多了</span>
      </div>
    </div>
    <div class="weui-loadmore" v-if="loading">
      <i class="weui-loading"></i>
      <span class="weui-loadmore__tips">正在加载</span>
    </div>
    <div v-show="!loading && nodes.length <= 0" class="datalist nodata">没有审批记录哦~</div>
  </div>
</template>

<script>
  export default {
    name: 'TransOperationLogs3',
    data () {
      return {
        nodes: [],
        orderid: '',
        srguid: '',
        tosrguid: '',
        departid: '',
        sellformpid: '',
        sellformpcode: '',
        nodesHtml: '',
        userid: localStorage.userid,
        username: localStorage.username,
        loading: true
      }
    },
    mounted() {
      this.orderid = this.$route.query.orderid;
      this.srguid = this.$route.query.srguid;
      this.tosrguid = this.$route.query.tosrguid;
      this.departid = this.$route.query.departid;
      this.sellformpid = this.$route.query.sellformpid;
      this.sellformpcode = this.$route.query.sellformpcode;

      this.getOperatelogs();

      $('#wrap').on('click', '.logimg', function () {
        let num = $(this).parent().children().length;
        let imgArr = [];
        for (var i=0; i<num; i++) {
          imgArr.push($(this).parent().find('.logimg').eq(i).data('img'));
        }
        let index = $(this).index();
        let pb3 = $.photoBrowser({
          items: imgArr,
          initIndex: index
        });
        pb3.open();
      });

    },
    watch: {
      // 'orderid': function (val) {
      //   this.getOperatelogs();
      // },
      // 'srguid': function (val) {
      //   this.getOperatelogs();
      // },
      // 'departid': function (val) {
      //   console.log('departid:', this.departid)
      //   this.getOperatelogs();
      // },
    },
    methods: {
      getOperatelogs: function (id) {
        if (this.orderid == undefined || this.srguid == undefined || this.departid == undefined) return;
        this.axios({
          method: 'get',
          url: '/sales/Flowtempnode!getTransferFlowNodes.action',
          params: {guid: this.orderid, srguid: this.srguid, toSrguid: this.tosrguid, departid: this.departid}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.loading = false;

            let data = response.data;
            //this.$nextTick(function () {
            this.nodes = data.nodes;
            let pendNodes = this.nodes.filter(item => {
              return item.status == 2;
            })
            this.initNodesSelect(pendNodes);
            //})
          } else {
            //this.toastText('获取审批记录失败');
          }
        });
      },
      showEdit: function(opers, status) {
        let operIds = opers.map(item => {
          return item.guid;
        });
        return operIds.indexOf(this.userid) > -1 && status == 1;
      },
      packIt: function(obj) {
        if (obj != '') {
          return JSON.parse(obj);
        } else {
          return [];
        }
      },
      editIt: function(id){
        let that = this;
        $.modal({
          title: "提示信息",
          text: this.nodesHtml,
          buttons: [
            { text: "确定", onClick: function(){
                if ($('#remark').val() == '') {
                  that.toastText('请输入信息内容！');
                  return false;
                }
                //防止重复提交
                $('.subbtn').attr("disabled",true).css("pointer-events","none");
        //显示提交状态
        $.showLoading("正在提交");

                let postData = {
                  toNodeid: $('#tonode').val(),
                  optlogid: id,
                  remark: $('#remark').val(),
                  operatorid: that.userid,
                  operator: that.username
                }
                that.axios({
                  method: 'post',
                  url: '/sales/Operationlogs!appendRemark.action',
                  params: postData
                }).then(response => {
                  //恢复提交按钮可点击
                  $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          //关闭提交状态
          $.hideLoading();

                  if (response.data.msg == 'success') {
                    that.toastSuccess("保存成功");
                    $.closeModal();
                    location.reload();
                  } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
                    //不不设置提示
                  } else {
                    that.toastError('系统错误');
                  }
                }).catch(function (error) {
                  //恢复提交按钮可点击
                  $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          //关闭提交状态
          $.hideLoading();
                  that.toastError('系统错误');
                });
              }},
            { text: "取消", className: "default"},
          ]
        });
      },
      initNodesSelect: function (arr) {
        let content = '<div class="cellgroup"> <div class="weui-cell weui-cell_select fir"> <div class="weui-cell__hd"><label class="weui-label">提醒对象</label></div> <div class="weui-cell__bd"> <select class="weui-select" name="" id="tonode"> <option value="" disabled>请选择</option>';
        for (let i=0; i<arr.length; i++) {
          content += '<option value="'+ arr[i].guid +'">'+ arr[i].name +'</option>';
        }
        content += '</select> </div> </div> <div class="weui-cell"> <div class="weui-cell__hd"><label class="weui-label">信息</label></div> <div class="weui-cell__bd"> <textarea id="remark" class="weui-textarea" name="" placeholder="请输信息内容" rows="2"></textarea> </div> </div> </div>';
        this.nodesHtml = content;
      },
      filterNull: function (obj) {
        return obj != null ? obj : {};
      },
      openLogs: function() {
        this.$router.push({name: 'OperationLogs2', query: {orderid: this.id, srguid: this.sellform.storermguid, departid: this.sellform.depguid}});
      }
    }
  }
</script>
